package com.gem.day05.exercise;

import java.util.Arrays;

/**员工实体类*/
//实体类 和 业务类 合二为一
public class Employee {
	//基础属性
	private String empNo;
	private String name;
	private double salary;

	//自关联
	//private Employee manager;//上司
	private Employee[] employees;//下属数组

	public Employee() {
		super();
	}

	public Employee(String empNo, String name, double salary) {
		super();
		this.empNo = empNo;
		this.name = name;
		this.salary = salary;
	}

	public Employee(String empNo, String name, double salary, Employee[] employees) {
		super();
		this.empNo = empNo;
		this.name = name;
		this.salary = salary;
		this.employees = employees;
	}

	public String getEmpNo() {
		return empNo;
	}

	public void setEmpNo(String empNo) {
		this.empNo = empNo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getSalary() {
		return salary;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}

	public Employee[] getEmployees() {
		return employees;
	}

	public void setEmployees(Employee[] employees) {
		this.employees = employees;
	}

	@Override
	public String toString() {
		String result = "Employee [empNo=" + empNo + ", name=" + name + ", salary=" + salary + "]";
		if (employees != null && employees.length != 0) {
			result += "\n该员工的下属:\n";
			//说明当前员工具有若干个下属
			for (Employee e : employees) {
				result += e + "\n";
			}
		}
		return result;
	}

	/**
	 * 添加下属的方法
	 */
	public void addEmp(Employee newEmp) {
		employees = Arrays.copyOf(employees, employees.length + 1);
		employees[employees.length - 1] = newEmp;
	}

	/**
	 * 获取自己下属的人数个数
	 */
	public int countEmp() {
		if (employees != null) {
			return employees.length;
		}
		return 0;
	}
}
